var xzyn = {
	msgs:'',	//消息框实例
	msg:function (infos= '提示',types='s',closes='',times=1.8,centers=true){//提示消息框  msg(内容,type:s/e/w/i/l,回调,时间,中间显示)
		if( closes == ''){
			this.msgs = msg({text:infos,type:types,time:times,center:centers});
		}else{
			this.msgs = msg({text:infos,type:types,close:closes,time:times,center:centers});
		}
	},
	gbMsg:function (){	//关闭消息框
		this.msgs.out();
	},
	getCookie:function (cname) {	//获取cookie
	    var name = cname + "=";
	    var ca = document.cookie.split(';');
	    for(var i = 0; i < ca.length; i++) {
	        var c = ca[i].trim();
	        if(c.indexOf(name) == 0) return c.substring(name.length, c.length);
	    }
	    return "";
	},
	setCookie:function (cname, cvalue, exdays) {	//设置cookie setCookie(名称,值,过期时间)
	    var d = new Date();
	    d.setTime(d.getTime() + (exdays * 1000));
	    var expires = "expires=" + d.toGMTString();
	    document.cookie = cname + "=" + cvalue + "; " + expires;
	},
	iconArr:function (){	//获取icon图标数组
    	var iconlistarr = [];
	    if (iconlistarr.length == 0 ) {
		    $.get("/static/xzyn/css/variables.less", function (ret) {
		        var exp = /fa-var-(.*):/ig;
		        var result;
		        while ((result = exp.exec(ret)) != null) {
		            iconlistarr.push('fa-' + result[1]);
		       	}
		   });
		}
	    return iconlistarr;
	},
	daojishi:function (time=10,demo='',text='剩余'){		//倒计时
    	var timer = null;
       	var num=time;
       	var tests = $(demo).text();
		$(demo).attr("disabled",'disabled');
		var href = $(demo).attr('href');
		if( href != null){
			$(demo).removeAttr('href',false);
		}
       	timer = setInterval(function() {
            $(demo).text(text+'('+num+')秒');// 你倒计时显示的地方元素
            num--;
            if(num < 0){
                clearInterval(timer);
                $(demo).attr("disabled", false);
                if( href != null){
					$(demo).attr('href',href);
				}
				$(demo).text(tests);
            }
        },1000);
    }

}

//jquery扩展
$.fn.extend({
    x_open_dh: function (animationName,animationOutName='',xopen,xback) {
	    var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
    	if(!animationOutName){	//点击添加动画
	        $(this).addClass('donghua ' + animationName).one(animationEnd, function() {
	            $(this).removeClass('donghua ' + animationName);
	        });
    	}else{
    		if($(this).css('display') == 'none'){	// 显示/隐藏
    			$(this).css('display','block');
    			$(this).addClass('donghua ' + animationName).one(animationEnd, function() {
		            $(this).removeClass('donghua ' + animationName);
		            if(xopen){
						xopen();
					}
		        });
    		}else{
    			$(this).addClass('donghua ' + animationOutName).one(animationEnd, function() {
		            $(this).removeClass('donghua ' + animationOutName);
    				$(this).css('display','none');
					if(xback){
						xback();
					}
		        });
    		}
    	}
    },
    x_delimg:function(){
    	var _this = $(this);
    	var imgurl = _this.find('img').attr('src');
		$.ajax({
    	    url: "/index/uploads/delete", //请求url
    	    type: "post",  //请求的类型
    	    dataType: "json",  //数据类型
    	    data: {'del_url':imgurl,'dir':'file'}, //发送到服务器的数据
    	    success:function(data) { //成功后执行
    	        if(data.code == 200){
    	        	xzyn.msg(data.msg);
    	        	_this.remove();
    	        }else{
    	        	xzyn.msg(data.msg);
    	        }
    	    },
    	    error:function(data) { //失败后执行
    	        console.log(data);
    	    }
    	});
    }
});



// 消息提示  msg({'text':'消息文字'})
// text 消息文字
// time 消息停留时间,0为不会关闭, 设置为0表示不自动消失，可调用 msg()方法返回的实例的 out()方法手动控制消失
// type 图标类型(s,e,w,i,l)
// mask 消息显示期间是否锁定屏幕 true|false
// alone 设为true会让此条消息消失之前，其它消息都无法显示 true|false
// center true 在中间显示, false 在顶部显示
// open 消息显示后的回调函数
// close 消息消失后的回调函数.
!(function(){var Message=function(option){var _this=this;var def_options={text:'提示',time:1.8,mask:false,alone:false,type:'',center:true,open:function(){},close:function(){}};_this.opts=extend(def_options,option);if(_this.opts.alone==true){Message.alone=true}_this.enter()};Message.message_wrapper=null;Message.zIndex=2060;Message.alone=false;Message.prototype.enter=function(){var _this=this;if(!Message.message_wrapper){Message.message_wrapper=document.createElement('div');addClass(Message.message_wrapper,'artMessage-wrapper');Message.message_wrapper.style.zIndex=Message.zIndex;document.body.appendChild(Message.message_wrapper)}if(_this.opts.mask&&_this.check_backdrop()===0){var backdrop=document.createElement('div');addClass(backdrop,'artMessage-backdrop');backdrop.style.zIndex=Message.zIndex-1;document.body.appendChild(backdrop)}_this.opts.open.call(_this);var type=document.createElement('i');switch(_this.opts.type){case 's':addClass(type,'success');break;case 'e':addClass(type,'error');break;case 'w':addClass(type,'warn');break;case 'i':addClass(type,'info');break;case 'l':addClass(type,'loading');break;default:type.style.display='none'}var custom_msg=document.createElement('span');addClass(custom_msg,'custom-msg');custom_msg.innerHTML=_this.opts.text;var content=document.createElement('div');addClass(content,'artMessage-content');content.appendChild(type);content.appendChild(custom_msg);_this.messageItem=document.createElement('div');addClass(_this.messageItem,'artMessage-item');if(_this.opts.center==true){_this.messageItem.style.position='relative';_this.messageItem.style.top=Math.floor(getViewportSize().h*0.38)+'px'}_this.messageItem.appendChild(content);Message.message_wrapper.appendChild(_this.messageItem);addClass(_this.messageItem,'move-up-enter');addClass(_this.messageItem,'move-up-enter-active');setTimeout(function(){removeClass(_this.messageItem,'move-up-enter');removeClass(_this.messageItem,'move-up-enter-active')},200);if(_this.opts.time!==0){setTimeout(function(){_this.out()},_this.opts.time*1000)}};Message.prototype.out=function(){var _this=this;addClass(_this.messageItem,'move-up-leave');addClass(_this.messageItem,'move-up-leave-active');setTimeout(function(){_this.messageItem.parentNode.removeChild(_this.messageItem);_this.opts.close.call(_this);if(_this.check_backdrop()>0&&_this.opts.mask){var backdrop_elements=getElementsByAttribute('class','artMessage-backdrop');for(var i=0,len=backdrop_elements.length;i<len;i+=1){backdrop_elements[i].parentNode.removeChild(backdrop_elements[i])}}Message.alone=false},200)};Message.prototype.check_backdrop=function(){var backdrop_elements=getElementsByAttribute('class','artMessage-backdrop');return backdrop_elements.length};var msg=function(option){if(Message.alone===true){return false}return new Message(option)};function getViewportSize(w){w=w||window;if(w.innerWidth!=null){return{w:w.innerWidth,h:w.innerHeight}}else{var d=w.document;if(document.compatMode=="CSS1Compat"){return{w:d.documentElement.clientWidth,h:d.documentElement.clientHeight}}else{return{w:d.body.clientWidth,h:d.body.clientHeight}}}}function getElementsByAttribute(attribute,attributeValue,queryElement){var elementArray=[];var matchedArray=[];var qElement=document;if(typeof queryElement!=='undefined'){qElement=queryElement}if(qElement.all){elementArray=qElement.all}else{elementArray=qElement.getElementsByTagName("*")}for(var i=0,len=elementArray.length;i<len;i+=1){if(attribute=="class"){var pattern=new RegExp("(\\s|^)"+attributeValue+"(\\s|$)");if(pattern.test(elementArray[i].className)){matchedArray[matchedArray.length]=elementArray[i]}}else if(attribute=="for"){if(elementArray[i].getAttribute("htmlFor")||elementArray[i].getAttribute("for")){if(elementArray[i].htmlFor==attributeValue){matchedArray[matchedArray.length]=elementArray[i]}}}else if(elementArray[i].getAttribute(attribute)==attributeValue){matchedArray[matchedArray.length]=elementArray[i]}}return matchedArray}function hasClass(elements,cName){return!!elements.className.match(new RegExp("(\\s|^)"+cName+"(\\s|$)"))}function addClass(elements,cName){if(!hasClass(elements,cName)){elements.className+=" "+cName}}function removeClass(elements,cName){if(hasClass(elements,cName)){elements.className=elements.className.replace(new RegExp("(\\s|^)"+cName+"(\\s|$)")," ")}}function extend(obj1,obj2){for(var k in obj2){obj1[k]=obj2[k]}return obj1}if(typeof define==='function'){define(function(){return msg})}else if(typeof exports!=='undefined'){module.exports=msg}else{this.msg=msg}})();




